﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="~/MainSys/Manager/Controls/ctManagementGroupUser.ascx.cs" Inherits="KhoaLuan.MainSys.Manager.Controls.ctManagementGroupUser" %>

<link href="../../../Style/StyleCommon.css" rel="stylesheet" />
<link href="../../../Style/modal.css" rel="stylesheet" />
<script src="/Scripts/dluscript.js"></script>
<script type="text/javascript">
    var currentGroup_User;
    var listGroup_User = [];

    function GetGroup_UserInList(id) {
        for (var i = 0; i < listGroup_User.length; i++) {
            if (listGroup_User[i].Group_UserID == id)
                return listGroup_User[i];
        }
        return null;
    }
    function LoadListGroup_User(totalitem, target, listgroup_user) {
        listGroup_User = listgroup_user;
        debugger;
        target.empty();
        listGroup_User.forEach(function (item) {
            var tr = $("<tr>");
            var td = $("<td>").append($('<input type="checkbox">'));
            tr.append(td);
            td = $("<td>").text(item.group);
            tr.append(td);
            td = $("<td>").text(item.user);
            tr.append(td);
            td = $("<td>");
            var btnedit = CreateButton(item.id, "fa-edit");
            btnedit.click(function () {
                currentGroup_User = GetGroup_UserInList($(this).attr('dataid'));
                var target = "/MainSys/Manager/GroupUser/AddNewGroup_User.aspx";
                $('#remoteModal').removeData();
                $("#remoteModal").load(target, function () {
                    $("#remoteModal").modal("show");
                });
            });
            td.append(btnedit);
            var btndel = CreateButton(item.id, "fa-times");
            btndel.click(function () {
                debugger;
                var id = $(this).attr("dataid");
                var sender = $(this);
                confirm("Xác nhận", "Bạn có muốn xóa user này không", "Xóa", "Hủy bỏ", function () {
                    debugger;
                    CallAjaxAspx("POST", "DeletetbGroupUser", "/MainSys/ProcessAJAX/AjaxGroup_User.aspx", { Group_UserID: parseInt(id) }, function (data) {
                        debugger;
                        var responseDel = JSON.parse(data);

                        if (responseDel.Status) {
                            debugger;
                            sender.parent().parent().remove();
                            alertSmallBox("Xóa thành công", "1 giây trước...");
                        }
                        else {
                            alertSmallBox("Xóa thất bại", "1 giây trước...", "error");
                        }
                    }, function () { }, function () { });
                });
            });
            td.append(btndel);
            tr.append(td);
            target.append(tr);
        });
    }
    function LoadData(page) {
        debugger;
        var numberinpage = 5;
        var keyword = $("#<%=txtTimKiem.ClientID%>").val();
        var dataagr = JSON.stringify({
            keyword: keyword,
            currentpage: parseInt(page),
            numberinpage: numberinpage
        });
        debugger;
        LoadDataWithPaging($("#tabletbGroupUser > tbody"), $("#divpaging"), page, "POST", "/MainSys/ProcessAJAX/AjaxGroup_User.aspx/GetListtbGroupUser", dataagr, LoadListGroup_User, numberinpage, LoadData);
    }
    $(document).ready(function () {
        debugger;
        LoadData(1);
        $("#<%=btnThem.ClientID%>").click(function () {
            currentGroup_User = null;
            var target = "/MainSys/Manager/GroupUser/AddNewGroup_User.aspx";
            $('#remoteModal').removeData();
            $("#remoteModal").load(target, function () {
                $("#remoteModal").modal("show");
            });
        });
    });

    function Import() {
        debugger;
        var datafile = new FormData();
        var files = $("#fileUpload").get(0).files;
        //// Add the uploaded image content to the form data collection
        if (files.length > 0) {
            datafile.append("File", files[0]);
        }
        datafile.append("TableName", "tbGroupUser");

        // Make Ajax request with the contentType = false, and procesDate = false
        $.ajax({
            type: "POST",
            url: "/ProcessAJAX/AJAXImport.ashx",
            contentType: false,
            processData: false,
            data: datafile,
            success: function (data) {
                var res = JSON.parse(data);
                if (res.Status == "Success") {
                    alert("Import thành công")
                    LoadTabletbGroupUser();
                }
                else {
                    alert("Import thất bại.")
                }
            }
        });

    }
</script>
<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1" data-widget-editbutton="false" data-widget-fullscreenbutton="false">


    <header>
        <h2>Manage Group User	</h2>
        <div class="widget-toolbar">
            <!-- add: non-hidden - to disable auto hide -->

            <div class="btn-group">
                <input class="btn btnthem dropdown-toggle btn-xs btn-success" type="button" id="btnThem" runat="server" style="margin-right: 10px;" value="Add new" />
                <input type="button" value="Show" class="btn btnthem dropdown-toggle btn-xs btn-success" onclick="LoadData(1);" />
            </div>
        </div>
    </header>

    <div>
        <div class="widget-body widget-hide-overflow padding">
            <div class="col-xs-12 col-sm-6">
                <div id="datatable_tabletools_filter" class="dataTables_filter">
                    <label style="float: left">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                        <input type="search" class="form-control" placeholder="input keyword" id="txtTimKiem" runat="server" />
                        <input type="button" onclick="LoadData(1);" value="Search" class="btn btn-default" style="width: 80px;" />
                    </label>
                </div>
            </div>
            <div class="col-sm-6 col-xs-6 hidden-xs" style="text-align: right;">
                <input type="file" id="fileUpload" accept="image/jpg" class="btn btn-default" />
                <input type="button" id="btnImport" runat="server" onclick="Import()" value="import" class="btn btn-default" />
            </div>

            <asp:Label ID="lblThongBao" runat="server" ForeColor="Red"></asp:Label>


            <table id="tabletbGroupUser" class="table table-bordered">
                <thead>
                    <tr>
                        <td></td>
                        <td>GroupId
                        </td>
                        <td>UserID
                        </td>
                        <td>Action
                        </td>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div id="divpaging"></div>
    </div>
</div>


